/*
 * Copyright (c) 2011 Jean-Marc Perronne
 * Ensisa, 12 rue des Freres Lumieres, F-68093 Mulhouse cedex
 * All rights reserved.
 *
 * The copyright of this software is owned by Werner Randelshofer. 
 * You may not use, copy or modify this software, except in  
 * accordance with the license agreement you entered into with  
 * Jean-Marc Perronne. For details see accompanying license terms. 
 */

package fr.uha.ensisa.jmp.drone.ui.instrument.dial.renderer;

import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Insets;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import fr.uha.ensisa.jmp.drone.ui.instrument.dial.Dial;


public class DefaultDialRenderer implements DialRenderer
{
	private final static Dimension DEFAULT_DIAL_SIZE = new Dimension(100,100);

	protected Dial dial;
	private Handler handler;
	private Dimension size;

	public DefaultDialRenderer(Dial dial)
	{
		this.dial = dial;
		this.handler = new Handler();
		this.size = DEFAULT_DIAL_SIZE;
		this.dial.addChangeListener(this.handler);
	}
	
	@Override
	public void renderTick(Graphics2D g)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void renderTicks(Graphics2D g)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void renderLabel(Graphics2D g)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void renderLabels(Graphics2D g)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void renderTrack(Graphics2D g)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void renderNeedle(Graphics2D g)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void renderBackground(Graphics2D g)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void renderDial(Graphics2D g)
	{
		if (this.dial.getModel().getPaintBackground()) this.renderBackground(g);
		if (this.dial.getModel().getPaintTrack()) this.renderTrack(g);
		if (this.dial.getModel().getPaintTicks()) this.renderTicks(g);
		if (this.dial.getModel().getPaintLabels()) this.renderLabels(g);
		this.renderNeedle(g);
	}
	
	public void setSize(Dimension size)
	{
		this.size = size;
	}
	
	public Dimension getSize()
	{
		return this.size;
	}

	public Dimension getPreferredSize()
	{
		Dimension d = this.getSize();
		Insets insetCache = this.dial.getInsets();

		d.width += insetCache.left + insetCache.right;
		d.height += insetCache.top + insetCache.bottom;

		return d;
	}

		public Dimension getMinimumSize()
	{
		return this.getPreferredSize();
	}
	
	public Dimension getMaximumSize()
	{
		Dimension d = new Dimension();
		d.height = Short.MAX_VALUE;
		d.width = Short.MAX_VALUE;
		return d;
	}

	//class Handler----------------------------
	private class Handler implements ChangeListener
	{
		@Override
		public void stateChanged(ChangeEvent arg0)
		{
			dial.repaint();
		}
	}
}
